﻿

using System;
using System.IO;
using WCFContract;



namespace WCFService
{
    /// <summary>
    /// 文件操作 实现 -- WCF分布式开发技术讲座_7_大数据传输和Streaming流处理
    /// </summary>
    public class FileOpeatorService:IFileOpeator
    {
        #region IFileOpeator Methons

        public void UpLoadFile(string fileName,MemoryStream stream)
        {
            Console.WriteLine("上传开始接收：" + DateTime.Now.ToString());
            var path = AppDomain.CurrentDomain.BaseDirectory + @"\" + fileName;
            FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate,FileAccess.ReadWrite);
            stream.WriteTo(fileStream);
            fileStream.Flush();
            fileStream.Close();
            fileStream.Dispose();
            Console.WriteLine("上传接收结束：" + DateTime.Now.ToString());
        }

        public void DownLoadFile(out MemoryStream stream, string fileName)
        {
            Console.WriteLine("开始下载：" + DateTime.Now.ToString());
            var path = AppDomain.CurrentDomain.BaseDirectory + @"\" + fileName;
            var fileBytes = File.ReadAllBytes(path);
            Console.WriteLine("字节大小：" + fileBytes.Length);
            stream = new MemoryStream(fileBytes);
            Console.WriteLine("下载结束：" + DateTime.Now.ToString());
        }

        #endregion

    }
}
